<template>
    <div class="trainPlanStuff">
      <el-form ref="newTrainContentForm" :model="newTrainContentForm" label-width="80px">
        <el-form-item label="课程编号" prop="courseID">
          <el-input v-model="newTrainContentForm.courseID"></el-input>
        </el-form-item>
        <el-form-item label="课程名称" prop="courseNameCN">
          <el-input v-model="newTrainContentForm.courseNameCN"></el-input>
        </el-form-item>
        <el-form-item label="英文名称" prop="courseNameEN">
          <el-input v-model="newTrainContentForm.courseNameEN"></el-input>
        </el-form-item>
        <el-form-item label="课程平台" prop="coursePlatform">
          <el-input v-model="newTrainContentForm.coursePlatform"></el-input>
        </el-form-item>
        <el-form-item label="课程性质" prop="courseNature">
          <el-select v-model="newTrainContentForm.courseNature" placeholder="请选择课程性质">
            <el-option label="考试课" value="考试课"></el-option>
            <el-option label="考察课" value="考察课"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学分" prop="credit">
          <el-input v-model="newTrainContentForm.credit"></el-input>
        </el-form-item>
        <el-form-item label="学时" prop="courseHour">
          <el-input v-model="newTrainContentForm.courseHour"></el-input>
        </el-form-item>
        <el-form-item label="授课时长" class="css-plus" prop="teachHour">
            <el-input label="授课" v-model="newTrainContentForm.teachHour"></el-input>
        </el-form-item>
        <el-form-item label="上机时长" class="css-plus" prop="computerHour">
            <el-input label="上机" v-model="newTrainContentForm.computerHour" ></el-input>
        </el-form-item>
        <el-form-item label="实验时长" class="css-plus" prop="experimentHour">
            <el-input label="实验" v-model="newTrainContentForm.experimentHour"></el-input>
        </el-form-item>
          <el-form-item label="实践时长" class="css-plus" prop="practiceHour">
            <el-input label="实践" v-model="newTrainContentForm.practiceHour" ></el-input>
        </el-form-item>
        <el-form-item label="学期" prop="term">
          <el-select v-model="newTrainContentForm.term" placeholder="请选择学期">
            <el-option label="01" value="01"></el-option>
            <el-option label="02" value="02"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学年" prop="academicYear">
           <el-select v-model="newTrainContentForm.academicYear" placeholder="请选择 学年" class="max-width">
               <el-option
                  v-for="item in yearList"
                  :label="item.yearName"
                  :value="item.yearID">
               </el-option>
            </el-select>

        </el-form-item>
        <el-form-item label="每周学时" prop="weeklyHour">
          <el-input v-model="newTrainContentForm.weeklyHour"></el-input>
        </el-form-item>
        <el-form-item label="计分方式" prop="scoringWay">
          <el-select v-model="newTrainContentForm.scoringWay" placeholder="请选择 学年" class="max-width">
               <el-option
                  v-for="item in wayList"
                  :label="item.wayName"
                  :value="item.wayID">
               </el-option>
              </el-select>
        </el-form-item>

        <el-form-item label="能力要求" prop="courseRequirement">
          <el-input v-model="newTrainContentForm.courseRequirement"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm()">保存</el-button>
          <el-button @click="resetForm('newTrainContentForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
</template>
<style>
  .css-plus .el-icon-plus:before {
    top:0;
    left:0;
    /*
      怎么删除一下这属性=-=。
    */
  }
  .class-assign {
    width: 50px;
    border-radius: 4px;
    border: 1px solid #bfcbd9;
    margin: 0 30px 0 10px;
    padding:2px 4px;
  }
</style>
<script>
    export default{
        name : 'trainPlanStuff',
        data(){
            return{
                newTrainContentForm: {
                	trainingCourseID:'',
                	trainingSchemeID:'',
                    courseID: '',
                    courseNameCN: '',
                    courseNameEN: '',
                    coursePlatform: '',
                    courseNature: '',
                    credit: '',
                    courseHour: '',
                    teachHour: '',
                    computerHour: '',
                    practiceHour: '',
                    academicYear: '',
                    term: '',
                    weeklyHour: '',
                    scoringWay: '',
                    courseRequirement:''
                },
                yearList:[],
                wayList:[]
            }
        },
        components:{
        },
        mounted:function(){
            this.$nextTick(function(){
				this.getYearList();
				this.getWayList();
				this.res();
            })
        },
         methods: {
	         res(){
		        var trainingCourseID = this.$route.query.trainingCourseID;
		        this.$http.post(`http://localhost:8080/TeachingMIS/trainingCourse/getCourseByID`, {
		          trainingCourseID: trainingCourseID
		        }).then((res) => {
		          // 响应成功回调
		          console.log(res.body)
		          this.newTrainContentForm = res.body;
		        }, (err) => {
		          // 响应错误回调
		          console.log("服务器异常！");
		        })
	      	},
            getYearList(){
        		this.$http.get(`http://localhost:8080/TeachingMIS/common/getAcademicYear`)
		          .then((res) => {
		            console.log(res)
		            this.yearList = res.body
		          }, (err) => {
		            // 响应错误回调
		            //console.log(err)
		          })
      		},
      		getWayList(){
        		this.$http.get(`http://localhost:8080/TeachingMIS/common/getScoringWay`)
		          .then((res) => {
		            console.log(res)
		            this.wayList = res.body
		          }, (err) => {
		            // 响应错误回调
		            //console.log(err)
		          })
      		},
            //表单操作
            submitForm() {
            	alert(this.newTrainContentForm.trainingCourseID == undefined);
            	if(this.newTrainContentForm.trainingCourseID == undefined){
	            	this.newTrainContentForm.trainingSchemeID = this.$route.query.trainingSchemeID;
            	}
	            alert(this.newTrainContentForm.trainingSchemeID);
                this.$http.post('http://localhost:8080/TeachingMIS/trainingCourse/saveCourse',this.newTrainContentForm).then((response) => {
                    this.$notify({
                        title:"成功",
                        message:"保存课程成功",
                        type:"success"
                    });
                    alert("保存课程成功");
                }).catch(function(response){
                     alert("保存课程失败");
                })
            },
            resetForm(formName) {
              this.$refs[formName].resetFields();
            }
         }
    }
</script>
